package com.jlcindia.hibernate;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.hibernate.*;

import com.jlcindia.dao.CandidateDAO;
import com.jlcindia.dao.DAOFactory;

public class CLab18 {
	public static void main(String args[]) {
		CandidateDAO cdao = DAOFactory.getCandidateDAO();

		// 1.Adding FreshCandidate
		List<String> emails = new ArrayList<String>();
		emails.add("aa@jlc");
		emails.add("bb @jlc");

		Map<String, Double> pers = new HashMap<String, Double>();
		pers.put("M.Sc", new Double(99.99));
		pers.put("B.Sc", new Double(88.88));

		FreshCandidate fc = new FreshCandidate("ss", "dd", emails, "M.Sc",
				"10-10-10", 2010, pers, "Yes");
		cdao.addCandidate(fc);

		// 2.Adding ExpCandidate
		Set<String> sks = new HashSet<String>();
		sks.add("java");
		sks.add("JDBC");
		sks.add("JSP");

		List<String> cms = new ArrayList<String>();
		cms.add("JLC1");
		cms.add("JLC2");
		cms.add("JLC3");

		ExpCandidate ec = new ExpCandidate("sd", "sd", emails, "B.Sc",
				"11-11-11", 11, sks, cms, 9.9);
		cdao.addCandidate(ec);

		// 3. Loading freshCandidate
		FreshCandidate fcan = (FreshCandidate) cdao.getCandidateByCid(1);
		System.out.println(fcan.getCid());
		System.out.println(fcan.getFname());
		System.out.println(fcan.getLname());
		System.out.println(fcan.getQualification());
		System.out.println(fcan.getEmails());
		System.out.println(fcan.getDob());
		System.out.println(fcan.getYop());
		System.out.println(fcan.getYearGaps());
		System.out.println(fcan.getPercentages());

		// 3. Loading ExpCandidate
		ExpCandidate ecan = (ExpCandidate) cdao.getCandidateByCid(2);
		System.out.println(ecan.getCid());
		System.out.println(ecan.getFname());
		System.out.println(ecan.getLname());
		System.out.println(ecan.getQualification());
		System.out.println(ecan.getEmails());
		System.out.println(ecan.getDob());
		System.out.println(ecan.getYoe());
		System.out.println(ecan.getCompanies());
		System.out.println(ecan.getCtc());
		System.out.println(ecan.getSkills());

		// 5. Deleting FreshCandidates
		cdao.deleteCandidate(7);

		// 6. Deleting ExpCandidates
		cdao.deleteCandidate(6);

		// 7.updating FreshCandidates
		FreshCandidate fcan1 = (FreshCandidate) cdao.getCandidateByCid(1);
		fcan1.setFname("Sri");
		fcan1.setLname("vas");
		cdao.updateCandidate(fcan1);

		// 8. Updating Expcandidate
		ExpCandidate ecan1 = (ExpCandidate) cdao.getCandidateByCid(2);
		ecan1.setFname("sss");
		ecan1.setLname("ddd");
		cdao.updateCandidate(ecan1);

		// 9.Loadind AllCandidate
		List<Candidate> cans = cdao.getAllCandidates();
		for (Candidate candidate : cans) {
			System.out.println(candidate.getCid() + "\t" + candidate.getFname()
					+ "\t" + candidate.getLname() + "\t"
					+ candidate.getQualification());
		}

	}

}
